package code.whmmm.util.http.impl.requestimpl;

import code.whmmm.util.http.RequestHandler;

import java.util.Map;

/**
 * <p><b>
 * 表单 提交 <br/>
 * <b>contentType = application/x-www-form-urlencoded</b><br/>
 * <b>注意，没有启用 url encode！！！！，如果需要，请自行 url_encode</b>
 * </b></p>
 * <br/>
 *
 * @author Zero
 * @date 2019/8/2 13:35
 */
public class FormReqHandler implements RequestHandler {


    @Override
    public String process(Map<String, Object> params) {
        StringBuilder sb = new StringBuilder();
        if (params != null) {
            for (String it : params.keySet()) {
                Object o = params.get(it);
                String v = "";
                if (o != null) {
                    v = o.toString();
                }
                sb.append(it).append("=").append(v).append("&");
            }
        }
        if (sb.length() > 1) {
            sb.deleteCharAt(sb.length() - 1);
        }

        return sb.toString();
    }


}
